<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">
<meta name="referrer" content="same-origin">
<meta name="referrer" content="no-referrer" />








<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Netty之旅," />










<meta name="description" content="数据结构&amp;emsp;&amp;emsp;PoolChunk的设计借鉴了Buddy算法的核心，它内部通过byte数组memoryMap来构建一颗完全二叉树：1234567891011120                       1                       / \                      /   \1                    2      3">
<meta name="keywords" content="Netty之旅">
<meta property="og:type" content="article">
<meta property="og:title" content="Netty之旅（四）ByteBuf内存管理之PoolChunk">
<meta property="og:url" content="http://yoursite.com/2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/index.html">
<meta property="og:site_name" content="矩阵编程">
<meta property="og:description" content="数据结构&amp;emsp;&amp;emsp;PoolChunk的设计借鉴了Buddy算法的核心，它内部通过byte数组memoryMap来构建一颗完全二叉树：1234567891011120                       1                       / \                      /   \1                    2      3">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-24T16:22:00.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Netty之旅（四）ByteBuf内存管理之PoolChunk">
<meta name="twitter:description" content="数据结构&amp;emsp;&amp;emsp;PoolChunk的设计借鉴了Buddy算法的核心，它内部通过byte数组memoryMap来构建一颗完全二叉树：1234567891011120                       1                       / \                      /   \1                    2      3">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/"/>





  <title>Netty之旅（四）ByteBuf内存管理之PoolChunk | 矩阵编程</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?7d29e6fba8e07d1a8af2414a20e5f2a6";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">矩阵编程</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-主页">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-主页"></i> <br />
            
            主页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-分类"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-所有文章">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-文章"></i> <br />
            
            所有文章
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="matrix">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="矩阵编程">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Netty之旅（四）ByteBuf内存管理之PoolChunk</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-08-08T21:27:24+08:00">
                2018-08-08
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Netty之旅/" itemprop="url" rel="index">
                    <span itemprop="name">Netty之旅</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="数据结构"><a href="#数据结构" class="headerlink" title="数据结构"></a>数据结构</h3><p>&emsp;&emsp;PoolChunk的设计借鉴了Buddy算法的核心，它内部通过byte数组memoryMap来构建一颗完全二叉树：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">0                       1</span><br><span class="line">                       / \</span><br><span class="line">                      /   \</span><br><span class="line">1                    2      3</span><br><span class="line">                    / \    / \</span><br><span class="line">                   /   \  /   \</span><br><span class="line">2                 4     5 6    7</span><br><span class="line">                         *</span><br><span class="line">                         *</span><br><span class="line">                         *</span><br><span class="line">               / \              / \</span><br><span class="line">11         2048   2049  *** 4094   4095</span><br></pre></td></tr></table></figure></p>
<a id="more"></a>
<p>左边的数字代表二叉树的深度（注意深度从0开始），在PoolChunk中由一个byte数组depthMap维护，右边的数字表示节点序号（注意节点序号从1开始），是memoryMap数组和depthMap数组的下标，初始memoryMa和depthMap存储的内容完全一致。在Netty中一页的大小为8KB，即 Netty之旅（三）中<strong>DEFAULT_PAGE_SIZE=8192</strong>。假设需要分配8K大小的空间，首先从2048节点查看，如果该节点未被分配，直接使用该节点，并设置该节点memoryMap[2048]=12，表示该节点已经分配过内存了。也就是说，当一个节点被分配的时候，该节点的memoryMap值会+1，而且，这里还会递归遍历他的父节点，父节点memoryMap的值（节点深度）会取两个子节点较小的值，节点信息变化如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">10           10:10             10:11</span><br><span class="line">             /   \    ------&gt;  /   \</span><br><span class="line">11       11:11   11:11     11:12   11:11</span><br></pre></td></tr></table></figure></p>
<p>上面10:10表示深度为10的某个节点，分别在depthMap中的值和memoryMap中的值，他们初始深度都为10。左边深度为11的节点分配内存后，memoryMap的值+1为12，其父节点memoryMap的值会取两个子节点中较小的深度，变为11……而且该父节点也会一直往上递归，更改memoryMap值的大小。</p>
<h3 id="源码实现"><a href="#源码实现" class="headerlink" title="源码实现"></a>源码实现</h3><p>&emsp;&emsp;看一下PoolChunk分配内存的方法：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">long allocate(int normCapacity) &#123;</span><br><span class="line">    if ((normCapacity &amp; subpageOverflowMask) != 0) &#123; // &gt;= pageSize</span><br><span class="line">        return allocateRun(normCapacity);</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        return allocateSubpage(normCapacity);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这个方法很简单，如果分配的内存小于一页，就调用<strong>allocateSubpage</strong>，否则使用<strong>allocateRun</strong>，这里主要看下<strong>allocateRun</strong>方法：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">private long allocateRun(int normCapacity) &#123;</span><br><span class="line">        // 计算出分配normCapacity大小内存的节点的深度</span><br><span class="line">        int d = maxOrder - (log2(normCapacity) - pageShifts);</span><br><span class="line">        // 寻找可用的节点</span><br><span class="line">        int id = allocateNode(d);</span><br><span class="line">        if (id &lt; 0) &#123;</span><br><span class="line">            return id;</span><br><span class="line">        &#125;</span><br><span class="line">        freeBytes -= runLength(id);</span><br><span class="line">        return id;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>这里normCapacity必须是二次幂的，maxOrder参照 Netty之旅（三）初始为<strong>DEFAULT_MAX_ORDER=11</strong>，即我们二叉树的深度，这里利用二次幂的特性，使用位运算很巧妙地计算出当前分配内存的节点深度。看下<strong>pageShifts</strong>大小：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// 这里默由默认的pageSize=8192可推算出，默认的pageShifts=13</span><br><span class="line">private static int validateAndCalculatePageShifts(int pageSize) &#123;</span><br><span class="line">        ...(省略部分代码)</span><br><span class="line">        // Logarithm base 2. At this point we know that pageSize is a power of two.</span><br><span class="line">        return Integer.SIZE - 1 - Integer.numberOfLeadingZeros(pageSize);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>Integer.numberOfLeadingZeros是JDK自带方法，看下这个函数：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">// 这个函数的核心是算出int类型最高非零位前面的零位有几个</span><br><span class="line">public static int numberOfLeadingZeros(int i) &#123;</span><br><span class="line">        // HD, Figure 5-6</span><br><span class="line">        if (i == 0)</span><br><span class="line">            return 32;</span><br><span class="line">        int n = 1;</span><br><span class="line">        if (i &gt;&gt;&gt; 16 == 0) &#123; n += 16; i &lt;&lt;= 16; &#125;</span><br><span class="line">        if (i &gt;&gt;&gt; 24 == 0) &#123; n +=  8; i &lt;&lt;=  8; &#125;</span><br><span class="line">        if (i &gt;&gt;&gt; 28 == 0) &#123; n +=  4; i &lt;&lt;=  4; &#125;</span><br><span class="line">        if (i &gt;&gt;&gt; 30 == 0) &#123; n +=  2; i &lt;&lt;=  2; &#125;</span><br><span class="line">        n -= i &gt;&gt;&gt; 31;</span><br><span class="line">        return n;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>再来看下<strong>log2()</strong> 函数，和计算<strong>pageShifts</strong>的方法如出一辙：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">private static final int INTEGER_SIZE_MINUS_ONE = Integer.SIZE - 1;</span><br><span class="line">...</span><br><span class="line">private static int log2(int val) &#123;</span><br><span class="line">        // compute the (0-based, with lsb = 0) position of highest set bit i.e, log2</span><br><span class="line">        return INTEGER_SIZE_MINUS_ONE - Integer.numberOfLeadingZeros(val);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>真是高并发的教学典范，尽量使用位操作代替数学运算吧，对照诸如HashMap和redis字典容量的实现，都是基于二次幂。优秀的设计，总是有迹可循。<br>&emsp;&emsp;获得了二叉树的深度，继续看allocateNode如何获取节点：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">// 这个方法是在memoryMap中获取可用的node节点</span><br><span class="line">private int allocateNode(int d) &#123;</span><br><span class="line">    int id = 1;</span><br><span class="line">    // 将高位补1</span><br><span class="line">    int initial = - (1 &lt;&lt; d); // has last d bits = 0 and rest all = 1</span><br><span class="line">    // 获取根节点的深度，如果根节点深度大于当前节点，无法分配内存了</span><br><span class="line">    byte val = value(id);</span><br><span class="line">    if (val &gt; d) &#123; // unusable</span><br><span class="line">        return -1;</span><br><span class="line">    &#125;</span><br><span class="line">    // 如果当前深度val小于深度d 或者 当前节点id小于深度d最小的id</span><br><span class="line">    while (val &lt; d || (id &amp; initial) == 0) &#123; // id &amp; initial == 1 &lt;&lt; d for all ids at depth d, for &lt; d it is 0</span><br><span class="line">        // 深度+1</span><br><span class="line">        id &lt;&lt;= 1;</span><br><span class="line">        val = value(id);</span><br><span class="line">        // 如果当前深度大于d，证明该节点也不可用，去他的兄弟节点看看</span><br><span class="line">        if (val &gt; d) &#123;</span><br><span class="line">            // 节点序号 + 1</span><br><span class="line">            id ^= 1;</span><br><span class="line">            val = value(id);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    byte value = value(id);</span><br><span class="line">    assert value == d &amp;&amp; (id &amp; initial) == 1 &lt;&lt; d : String.format(&quot;val = %d, id &amp; initial = %d, d = %d&quot;,</span><br><span class="line">            value, id &amp; initial, d);</span><br><span class="line">    // 更新节点为不可用</span><br><span class="line">    setValue(id, unusable); // mark as unusable</span><br><span class="line">    // 顺便更新下他父节点的深度值</span><br><span class="line">    updateParentsAlloc(id);</span><br><span class="line">    return id;</span><br><span class="line">&#125;</span><br><span class="line">private byte value(int id) &#123;</span><br><span class="line">    return memoryMap[id];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>再看下如何更新父节点：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">// 递归该节点的父节点，更新父节点的memoryMap值为两个子节点中memoryMap较小的值</span><br><span class="line">private void updateParentsAlloc(int id) &#123;</span><br><span class="line">        while (id &gt; 1) &#123;</span><br><span class="line">            int parentId = id &gt;&gt;&gt; 1;</span><br><span class="line">            byte val1 = value(id);</span><br><span class="line">            byte val2 = value(id ^ 1);</span><br><span class="line">            byte val = val1 &lt; val2 ? val1 : val2;</span><br><span class="line">            setValue(parentId, val);</span><br><span class="line">            id = parentId;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>&emsp;&emsp;总结一下，从二叉树根节点往下开始遍历，如果该节点无法满足分配的内存大小，就跳到该节点的兄弟节点……一直到深度为d的某个节点，如果该节点还不可用，使用兄弟节点，最后设置选中的节点为不可用并递归更新父节点的深度。</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Netty之旅/" rel="tag"># Netty之旅</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/07/30/Java基础（一）CountDownLatch源码分析/" rel="next" title="Java并发之旅（一）CountDownLatch源码分析">
                <i class="fa fa-chevron-left"></i> Java并发之旅（一）CountDownLatch源码分析
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/08/08/Netty之旅（五）ByteBuf内存管理之PoolSubpage/" rel="prev" title="Netty之旅（五）ByteBuf内存管理之PoolSubpage">
                Netty之旅（五）ByteBuf内存管理之PoolSubpage <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="disqus_thread">
        <noscript>
          Please enable JavaScript to view the
          <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a>
        </noscript>
      </div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">matrix</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives">
              
                  <span class="site-state-item-count">47</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#数据结构"><span class="nav-number">1.</span> <span class="nav-text">数据结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#源码实现"><span class="nav-number">2.</span> <span class="nav-text">源码实现</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">matrix</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>
<div class=BbeiAn-info">
  浙ICP备 -
  <a href="http://www.beian.miit.gov.cn">18040498号</a>
  </a>
</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  

    
      <script id="dsq-count-scr" src="https://luyun.disqus.com/count.js" async></script>
    

    
      <script type="text/javascript">
        var disqus_config = function () {
          this.page.url = 'http://yoursite.com/2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/';
          this.page.identifier = '2018/08/08/Netty之旅（四）ByteBuf内存管理之PoolChunk/';
          this.page.title = 'Netty之旅（四）ByteBuf内存管理之PoolChunk';
        };
        var d = document, s = d.createElement('script');
        s.src = 'https://luyun.disqus.com/embed.js';
        s.setAttribute('data-timestamp', '' + +new Date());
        (d.head || d.body).appendChild(s);
      </script>
    

  




	





  














  





  

  

  

  
  

  

  

  

</body>
</html>
